# 38. 连续出牌数量
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let numbers = [];
let colors = [];
rl.on('line', (line) => {
if(!numbers.length) {
numbers = line.split(' ');
} else if(!colors.length) {
colors = input.split(' ');
const cards = new Array(numbers.length).fill(1);
let mx = 0;
for(let i=0; i<numbers.length; i++) {
cards[i] = 0;
mx = Math.max(dfs(numbers, colors, numbers[i], colors[i], cards), mx);
cards[i] = 1;
}
console.log(mx);
}
});
function dfs(nubmers, colors, last_num, last_color, cards) {
let deep = 0;
for(let i=0; i<cards.length; i++) {
if (cards[i] !== 0) {
if(numbers[i] === last_num || colors[i] === last_color) {
cards[i] = 0;
deep = Math.max(dfs(numbers, colors, numbers[i], colors[i], cards), deep);
cards[i] = 1;
}
}
}
return deep+1;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
← 37. 跳马 39. 部门人力分配 →